note
	description: "[
					Representation of a basic {US_PHONE} using a
					raw ten digit {STRING} representation.
					]"
	date: "$Date: $"
	revision: "$Revision: $"

class
	US_PHONE

inherit
	PHONE [US_PHONE_VALIDATOR, US_PHONE_FORMATTER]

create
	make_with_number,
	make_with_alpha

feature {NONE} -- Initialization

	make_with_number (a_number: attached like number_type_anchor)
			-- Initialization for `Current'.
		do
			create validator
			create formatter
			check valid_number: validator.is_valid (a_number) end
			number := a_number
			country_code := check_digit_1
		ensure
			number_set: number.same_string (a_number)
		end

	make_with_alpha (a_iso_number: attached like number_type_anchor)
			-- <Precursor>
		do
			make_with_number (iso_9995_8_number (a_iso_number))
		end

feature -- Status Report

	area_code: attached like number_type_anchor
			-- North American Area Code
			--| Only 10-digit numbers have area codes present.
		require
			has_seven_or_ten_digits: number.count = 10
		do
			Result := number.substring (1, 3)
		end

	exchange_code, central_office_number: attached like number_type_anchor
			-- Exchange or Central office code or number.
			--| Only 7 or 10-digit numbers have an exchange or central office code or number.
		require
			has_seven_or_ten_digits: number.count = 7 or number.count = 10
		do
			if number.count = 7 then
				Result := number.substring (1, 3)
			else
				Result := number.substring (4, 6)
			end
		end

	subscriber_number: attached like number_type_anchor
			-- Subscriber number of Current (e.g. "last four").
		require
			has_seven_or_ten_digits: number.count = 7 or number.count = 10
		do
			Result := number.substring (number.count - 3, number.count)
		end

feature -- Constants

	check_digit_0: STRING = "0"

	check_digit_1: STRING = "1"

	check_digit_9: STRING = "9"

invariant
	--| Removing this invariant, but leaving it to demonstrate that while we can guarentee
	--|		a valid number, we might not want to. We may well want to allow the loading of
	--|		invalid phone numbers from an external data source temporarily, while we work
	--|		to bring the number into compliance.
	-- valid_number: validator.is_valid (number)
	valid_country_code: country_code.same_string ("1")

note
	copyright: "Copyright (c) 2012-2012, Greater Atlanta User Group for Eiffel (GAUGE)"
	license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
	licensing_options: "http://www.eiffel.com/licensing"
	copying: "[
			This file is part of the Greater Atlanta User Group for Eiffel (GAUGE), Eiffel Development Environment.
			
			GAUGE's Eiffel Development Environment is free
			software; you can redistribute it and/or modify it under
			the terms of the GNU General Public License as published
			by the Free Software Foundation, version 2 of the License
			(available at the URL listed under "license" above).
			
			GAUGE's Eiffel Development Environment is
			distributed in the hope that it will be useful, but
			WITHOUT ANY WARRANTY; without even the implied warranty
			of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
			See the GNU General Public License for more details.
			
			You should have received a copy of the GNU General Public
			License along with Eiffel Software's Eiffel Development
			Environment; if not, write to the Free Software Foundation,
			Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
		]"
	source: "[
			GAUGE
			Atlanta, GA
			Website http://www.atlantausergroups.com/group/gauge
		]"
end
